﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using Vowei.Core.Models;
using Vowei.Data.Converters.Excel;
using Vowei.Data;
using System.Linq;
using Vowei.Data.Helpers;

namespace vowei.test.ScenarioTests
{
    /// <summary>
    /// DataTests 的摘要说明
    /// </summary>
    [TestClass]
    public class DataTests : TestBase
    {
        [TestMethod]
        public void ImportProjectDataBasicTest()
        {
            var filename = Path.Combine(
                TestContext.TestDeploymentDir, @"ExcelUserConverterTest_ConvertFromWbsFilesRealSenarioTest.xls");
            var target = new WorkItemExcelConverter(VoweiContext.TicketStatusManager);
            IEnumerable<ITable> items = null;
            Guid pid = Guid.Empty;

            using (var stream = File.Open(filename, FileMode.Open, FileAccess.Read))
            {
                items = target.ConvertFrom(stream);
            }

            using ( var impl = new VoweiContextImpl() )
            {
                var context = new VoweiContext(impl);
                var project = CreateProjectHelper("ImportProjectDataBasicTest");
                impl.Projects.Add(project);
                impl.SaveChanges();
                pid = project.ID;

                ImportHelper.ImportDataTo(project, context, items, Setting.DefaultFormUser);
            }

            using ( var impl = new VoweiContextImpl() )
            {
                var context = new VoweiContext(impl);
                var project = impl.Projects.Include("Children").Single(p => p.ID == pid);
                var tickets = project.AllTickets(context);
                Assert.AreEqual(6, project.Children.Count());
                Assert.AreEqual(33, project.AllRequirements(context).Count());
                Assert.AreEqual(129, tickets.Count());
                Assert.AreEqual(96, project.AllTickets(context).OfType<Task>().Count());
            }
        }
    }
}
